home *** CD-ROM | disk | FTP | other *** search
- % This is DVI_PS.PS version 0.60
- %
- % The following defines procedures assumed and used by program "dvi_ps".
- % Originated by Neal Holtz, Carleton University, Ottawa, Canada
- % <holtz@cascade.carleton.cdn>
- % June, 1985
- %
- % Hacked by tgr, July 1987, stripped down to bare essentials,
- % plus a few new commands for speed.
- %
- % Hacked by don, December 1989, to give characters top down and to
- % remove other small nuisances; merged with tgr's compression scheme
- %
- % Hacked by cs, September 1990, to adapt to dvi_ps conventions
- %
- % Hacked by cs, November 1990, to add EPSF includes
- %
- % To observe available VM, uncomment the following.
- % (The first ten lines define a general 'printnumber' routine.)
- %
- % /VirginMtrx 6 array currentmatrix def
- % /dummystring 20 string def
- % /numberpos 36 def
- % /printnumber { gsave VirginMtrx setmatrix
- % /Helvetica findfont 10 scalefont setfont
- % 36 numberpos moveto
- % /numberpos numberpos 12 add def
- % dummystring cvs show
- % grestore
- % } bind def
- % /showVM { vmstatus exch sub exch pop printnumber } def
- % /eop-aux { showVM } def
- %
-
- /TeXDict 200 dict def % define a working dictionary
- TeXDict begin % start using it.
-
- /bdf { bind def } def
-
- % The output of dvi_ps assumes pixel units, Resolution/inch, with
- % increasing y coordinates corresponding to moving DOWNWARD.
- % The PostScript default is big point units (bp), 72/inch, with
- % increasing y coordinates corresponding to moving UP; the
- % following routines handle conversion to dvi_ps conventions.
-
- % Let the PostScript origin be (xps,yps) in dvi_ps coordinates.
- /@rigin % -xps -yps @rigin - establishes dvi_ps conventions
- { 72 Resolution div 72 VResolution div neg scale
- translate
- } bdf
-
- % Here we assume the PostScript origin is at the bottom left corner
- % and that the paper is 11 inches high;
- % the dvi_ps origin is 1 inch from top left corner;
- % hence if Resolution=300, we have (xps,yps)=(-300,3000).
- /@letter % setup for standard letter format
- { Resolution VResolution -10 mul @rigin } bdf
-
- /@landscape
- { [ 0 1 -1 0 0 0 ] concat
- Resolution VResolution @rigin } bdf
-
- /@a4
- { Resolution VResolution -10.6929133858 mul @rigin } bdf
-
- /@legal
- { Resolution VResolution -13 mul @rigin } bdf
-
- /@manualfeed
- { statusdict /manualfeed true put
- } bdf
-
- % n @copies - set number of copies
- /@copies
- { /#copies exch def
- } bdf
-
- % Bitmap fonts are called fa, fb, ..., fz, f0, f1, ...; the maximum
- % supported by these macros is f999, but if you really go up that high
- % you need to increase the size of TeXDict.
- % The calling sequence for downloading font foo is
- % /foo df chardef1 ... chardefn dfe
- % where each chardef is
- % [<hexstring> wd ht xoff yoff dx] charno dc
-
- /@FontMatrix [1 0 0 -1 0 0] def
- /@FontBBox [0 0 0 0] def
- % alternative: /@FontBBox [0 0 1 1] def
-
- /@newfont % id @newfont - -- initialize a new font dictionary
- { /newname exch def
- pop
- newname 7 dict def % allocate new font dictionary
- newname load begin
- /FontType 3 def
- /FontMatrix @FontMatrix def
- /FontBBox @FontBBox def
- /BitMaps 256 array def
- /BuildChar {CharBuilder} def
- /Encoding IdentityEncoding def
- end
- % newname newname load definefont pop
- newname dup load definefont setfont
- } bdf
-
- % the following is the only character builder we need. it looks up the
- % char data in the BitMaps array, and paints the character if possible.
- % char data -- a bitmap descriptor -- is an array of length 6, of
- % which the various slots are:
-
- /ch-image {ch-data 0 get} bdf % the hex string image
- /ch-width {ch-data 1 get} bdf % the number of pixels across
- /ch-height {ch-data 2 get} bdf % the number of pixels tall
- /ch-xoff {ch-data 3 get} bdf % number of pixels to right of origin
- /ch-yoff {ch-data 4 get} bdf % number of pixels below origin
- /ch-dx {ch-data 5 get} bdf % number of pixels to next character
-
- /CharBuilder % fontdict ch Charbuilder - -- image one character
- {save 3 1 roll exch /BitMaps get exch get /ch-data exch def
- ch-data null ne
- {ch-dx 0 ch-xoff ch-yoff neg
- ch-xoff ch-width add ch-height ch-yoff sub
- setcachedevice
- ch-width ch-height true
- [1 0 0 -1 -.1 ch-xoff sub ch-height ch-yoff sub .1 add]
- % begin code for uncompressed fonts only
- {ch-image} imagemask
- }if
- restore
- } bdf
- % end code for uncompressed fonts only
- % % here's the alternate code for unpacking compressed fonts
- % /id ch-image def % image data
- % /rw ch-width 7 add 8 idiv string def % row, initially zero
- % /rc 0 def % repeat count
- % /gp 0 def % image data pointer
- % /cp 0 def % column pointer
- % { rc 0 ne { rc 1 sub /rc exch def rw } { G } ifelse } imagemask
- % }if
- % restore
- % } bdf
- % /G { { id gp get /gp gp 1 add def
- % dup 18 mod exch 18 idiv pl exch get exec } loop } bdf
- % /adv { cp add /cp exch def } bdf
- % /chg { rw cp id gp 4 index getinterval putinterval
- % dup gp add /gp exch def adv } bdf
- % /nd { /cp 0 def rw exit } bdf
- % /lsh { rw cp 2 copy get dup 0 eq { pop 1 } { dup 255 eq { pop 254 }
- % { dup dup add 255 and exch 1 and or } ifelse } ifelse put 1 adv } bdf
- % /rsh { rw cp 2 copy get dup 0 eq { pop 128 } { dup 255 eq { pop 127 }
- % { dup 2 idiv exch 128 and or } ifelse } ifelse put 1 adv } bdf
- % /clr { rw cp 2 index string putinterval adv } bdf
- % /set { rw cp fillstr 0 4 index getinterval putinterval adv } bdf
- % /fillstr 18 string 0 1 17 { 2 copy 255 put pop } for def
- % /pl [
- % { adv 1 chg } bind
- % { adv 1 chg nd } bind
- % { 1 add chg } bind
- % { 1 add chg nd } bind
- % { adv lsh } bind
- % { adv lsh nd } bind
- % { adv rsh } bind
- % { adv rsh nd } bind
- % { 1 add adv } bind
- % { /rc exch def nd } bind
- % { 1 add set } bind
- % { 1 add clr } bind
- % { adv 2 chg } bind
- % { adv 2 chg nd } bind
- % { pop nd } bind ] def
- % % end of code for unpacking compressed fonts
-
- % fontdict @sf - -- make that the current font
- /@sf
- { setfont
- } bdf
-
- % in the following, the font-cacheing mechanism requires that
- % a name unique in the particular font be generated
-
- /@dc % char-data ch dc - -- define character bitmap in current font
- { /ch-code exch def
- /ch-data exch def
- currentfont /BitMaps get ch-code ch-data put
- % newname load /BitMaps get ch-code ch-data put
- } bdf
-
- /@bop0 % n @bop0 - -- begin the char def section of a new page
- { (Page ) print == flush
- } def
-
- /@bop1 % n @bop1 - -- begin a brand new page
- { pop
- gsave /SaveImage save def
- 0 0 moveto
- } bdf
-
- /eop % - eop - -- end a page
- { % eop-aux % -- to observe VM usage
- clear SaveImage restore
- showpage grestore
- } bdf
-
- /@start % - @start - -- start everything
- {
- /VResolution exch def
- /Resolution exch def
- /IdentityEncoding 256 array def
- 0 1 255 {IdentityEncoding exch 1 string dup 0 3 index put cvn put} for
- } bdf
-
- /RuleMatrix [ 1 0 0 -1 -.1 -.1 ] def % things we need for rules
- /BlackDots 8 string def
- /v { % can't use ...fill; it makes rules too big
- gsave
- currentpoint translate
- false RuleMatrix { BlackDots } imagemask
- grestore
- } bdf
-
-
- /ru % dx dy ru - -- set a rule (rectangle)
- { /dy exch def
- /dx exch def
- % remember current point
- /x currentpoint /y exch def def
- newpath x y moveto
- dx 0 rlineto
- 0 dy rlineto
- dx neg 0 rlineto
- closepath fill
- x y moveto
- } bdf
-
- /p % x y p - -- move to position
- { moveto
- } bdf
-
- /r % x r - -- move right
- { 0 rmoveto
- } bdf
-
-
- /s % string s - -- show the string
- { show
- } bdf
-
- /c % ch c - -- show the character (code given)
- { c-string exch 0 exch put
- c-string show
- } bdf
-
- /c-string ( ) def
-
- %%%%%%%%%%%%%%%%%%%%% Lines for CS Graphics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- % dx dy @li - -- draw a line (to be used with CS-Graphics)
- /@li
- { /dy exch def
- /dx exch def
- /x currentpoint /y exch def def
- newpath
- x y moveto
- dx dy rlineto
- stroke
- x y moveto
- } bdf
-
- %%%%%%%%%%%%%%%%%%% Bit Images for CS Graphics %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
- % image width height xscale yscale @img - draw a bit image
- /@img
- {
- /img-yscale exch def
- /img-xscale exch def
- /img-height exch def
- /img-width exch def
- /img-image exch def
- gsave
- currentpoint translate
- img-width img-xscale mul img-height img-yscale mul scale
- img-width img-height true
- [img-width 0 0 img-height 0 img-height]
- {img-image} imagemask
- grestore
- /img-image <00> def % free the memory again
- } bdf
-
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% header for the \special{psfile=...} command
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % The structure of the PostScript produced by dvips for \special is:
- % @beginspecial
- % - any number of @hsize, @hoffset, @hscale, etc., commands
- % @setspecial
- % - the user's file of PostScript commands
- % @endspecial
-
- /SDict 200 dict def
- SDict begin
-
- /@SpecialDefaults
- { /hs 612 def
- /vs 792 def
- /ho 0 def
- /vo 0 def
- /hsc 1 def
- /vsc 1 def
- /ang 0 def
- /CLIP false def
- /BBcalc false def
- } bdf
-
- %
- % The following definition sets up the units that hscale/vscale are in.
- % For certain sites this might require change, but it is
- % recommended instead that any macro packages that require
- % hscale/vscale set the units appropriately via
- %
- % \special{! /@scaleunit 1 def }
- %
- % if global, or
- %
- % \special{" /@scaleunit 1 def }
- %
- % before each instance if multiple macro packages with
- % different requirements are being used.
- %
- /@scaleunit 100 def
- % s @hscale - set scale factor
- /@hscale {@scaleunit div /hsc exch def} bdf
- /@vscale {@scaleunit div /vsc exch def} bdf
-
- % d @hsize - specify a horizontal clipping dimension
- /@hsize {/hs exch def /CLIP true def} bdf
- /@vsize {/vs exch def /CLIP true def} bdf
-
- % d @hoffset - specify a shift for the figure
- /@hoffset {/ho exch def} bdf
- /@voffset {/vo exch def} bdf
-
- % a @angle - set rotation angle
- /@angle {/ang exch def} bdf
-
- %
- % Here we handle bounding box calculations, if necessary.
- %
- /@rwi { 10 div /rwi exch def } bdf % rwi will be real width after scaling
- /@llx { /llx exch def } bdf
- /@lly { /lly exch def } bdf
- /@urx { /urx exch def } bdf
- /@ury { /ury exch def /BBcalc true def } bdf
-
- end % of SDict
-
- % this will be invoked as the result of a \special command (for the
- % inclusion of PostScript graphics). The basic idea is to change all
- % scaling and graphics back to defaults, but to shift the origin
- % to the current position on the page.
-
- /@beginspecial % - @beginspecial - -- enter special mode
- { SDict begin
- /SpecialSave save def
- gsave
- Resolution 72 div dup neg scale
- currentpoint translate %set the current point as the user's origin
- @SpecialDefaults % setup default offsets, scales, sizes, and angle
- } bdf
-
- /@setspecial % to setup user specified offsets, scales, sizes (for clipping)
- {
- CLIP
- { newpath 0 0 moveto hs 0 rlineto 0 vs rlineto hs neg 0 rlineto
- closepath clip }
- { initclip }
- ifelse
- ho vo translate
- hsc vsc scale
- ang rotate
- BBcalc
- { rwi urx llx sub div dup scale
- llx neg lly neg translate }
- if
- /showpage {} def
- newpath
- } bdf
-
- /@endspecial % - @endspecial - -- leave special mode
- { grestore clear SpecialSave restore
- end
- } bdf
- /@defspecial
- {
- SDict begin
- } bdf
- /@fedspecial
- {
- end
- } bdf
-
- end % revert to previous dictionary
-